﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace GridViewPaging
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.IsPostBack == false)
            {
                BindInfo();
            }
        }

        private void BindInfo()
        {
            string connString = "server=.;database=Northwind;uid=sa;pwd=123456;";
            using (SqlConnection conn= new SqlConnection(connString))
            {
                string commString = "SELECT *  FROM [Categories]";
                SqlDataAdapter ada = new SqlDataAdapter(commString, conn);
                DataSet ds = new DataSet();
                ada.Fill(ds);

                this.GridView1.DataSource = ds.Tables[0].DefaultView;
                this.GridView1.DataBind();
            }
        }

        protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
        {
            //this.GridView1.PageIndex = e.NewSelectedIndex;
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.GridView1.PageIndex = e.NewPageIndex;
        }
    }
}